import { createSlice } from "@reduxjs/toolkit"
import { setCookie, getCookie } from "@/utils/cookie"

export const Token = createSlice({
  name: 'token',
  initialState: {
    value: (getCookie('token') || '') as string
  },
  reducers: {
    saveToken: (state, action) => {
       setCookie('token', action.payload)
       state.value = action.payload
    }
  }
})

export const { saveToken } = Token.actions
export default Token.reducer